package com.woniuxy.controller;


import com.woniuxy.entity.ClazzRoom;
import com.woniuxy.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/from")
public class FormSendParamsController {

    /**接收字符串传参**/
    @RequestMapping("/StringValue")
    public ModelAndView receiveParameters(String name){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("msg","当前接受的参数是"+name);
        modelAndView.setViewName("Text");
        return modelAndView;
    }


    /**接收前端from数组传参**/
    @RequestMapping("/ArrayValue")
    public ModelAndView receiveParameters(String[] ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ Arrays.toString(ids));
        modelAndView.setViewName("Text");
        return modelAndView;
    }


    /**传入一个数组，后端自动封装成List集合**/
    @RequestMapping("/ListValue")
    public ModelAndView receiveParameters(@RequestParam List<Integer> ids){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ ids);
        modelAndView.setViewName("Text");
        return modelAndView;
    }


    /** 传入一堆数据，后端自动封装成Map集合**/
    @RequestMapping("/MapValue")
    public ModelAndView receiveParameters(@RequestParam Map<String,Object> user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ user.toString());
        modelAndView.setViewName("Text");
        return modelAndView;
    }


    /**传入一堆数据，后端自动封装成User对象*/
    @RequestMapping("/UserValue")
    public ModelAndView receiveParameters(User user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ user.toString());
        modelAndView.setViewName("Text");
        return modelAndView;
    }


    /**复合对象数据传输*/
    @RequestMapping("/ClazzUserValue")
    public ModelAndView receiveParameters(ClazzRoom clazzRoom){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","接收到的前端参数是："+ clazzRoom.toString());
        modelAndView.setViewName("Text");
        return modelAndView;
    }
}
